package com.qinghua.health_project.controller.base;

import com.baomidou.mybatisplus.extension.service.IService;
import com.fwcloud.common.web.wrapper.ReturnWrapMapper;
import com.fwcloud.common.web.wrapper.ReturnWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @author LiuQinghua
 * @date 2023/2/7 22:33
 */
public abstract class BaseController<T> {
    @Autowired
    IService<T> service;

    @Autowired
    protected HttpServletRequest request;

    @ApiOperation(value = "根据Id获取记录", notes = "")
    @GetMapping("/getById")
    public ReturnWrapper getById(@RequestParam Long id) {
        return ReturnWrapMapper.ok(service.getById(id));
    }

    @ApiOperation(value = "根据Id删除记录", notes = "")
    @DeleteMapping("/deleteById")
    public ReturnWrapper deleteById(@RequestParam Long id) {
        return ReturnWrapMapper.ok(service.removeById(id));
    }
}
